# 6_3 屏幕使用：画点、划线、形状
# https://learn.adafruit.com/circuitpython-display-support-using-displayio
# https://learn.adafruit.com/circuitpython-display-support-using-displayio/ui-quickstart
# https://learn.adafruit.com/custom-fonts-for-pyportal-circuitpython-display
# https://github.com/adafruit/Adafruit_CircuitPython_Display_Shapes/tree/main/adafruit_display_shapes

'''
3. 画点、划线、形状
'''
import time
import board
import displayio

from adafruit_display_shapes.line import Line
from adafruit_display_shapes.rect import Rect
from adafruit_display_shapes.circle import Circle
from adafruit_display_shapes.roundrect import RoundRect
from adafruit_display_shapes.triangle import Triangle

# 1. 屏幕基础配置
display = board.DISPLAY

# 3. 画点、划线、形状
bitmap = displayio.Bitmap(display.width, display.height, 2)
palette = displayio.Palette(2)
palette[0] = 0x000000
palette[1] = 0xffffff

tile_grid = displayio.TileGrid(bitmap, pixel_shader=palette)
pixel_group = displayio.Group()
pixel_group.append(tile_grid)
display.show(pixel_group)

# 单个点
bitmap[80, 50] = 1

# 多个点
for x in range(50, 200, 10):
    bitmap[x, 100] = 1

time.sleep(3)

shape_group = displayio.Group()
# 点
line = Line(x0=5, y0=5, x1=200, y1=5, color=0x00FF00)
# 块
rect = Rect(x=10, y=10, width=30, height=20, fill=0x00FF00)
# 圆角块
roundrect = RoundRect(x=10, y=50, width=50, height=50, r=5, fill=0x0, outline=0xFF00FF, stroke=1)
# 圆角块
roundrect2 = RoundRect(x=70, y=50, width=50, height=50, r=5, fill=0x0, outline=0xFF00FF, stroke=5)
# 圆
circle = Circle(x0=200, y0=60, r=30, fill=0x00FF00, outline=0xFF00FF)

# 添加到显示组
shape_group.append(line)
shape_group.append(rect)
shape_group.append(roundrect)
shape_group.append(roundrect2)
shape_group.append(circle)

# 显示
display.show(shape_group)
time.sleep(10)
